$(document).ready(function() {
	mui.init();
	mui.plusReady(function() {
		setTimeout(function(){
			var vInfo = plus.push.getClientInfo();
			localStorage.setItem("cid", vInfo.clientid);
		},1000)
		muiBack();
		localStorage.setItem("firstPage", "");
		//判断本地是否有账号，如果有则使用当前账号
		if(localStorage.getItem("USERID")) {
			$("#account").val(localStorage.getItem("USERID"));
		}
		searchMerInfo();

		// 摄像头测试
		mui('body').on("tap", "#test", function() {
			console.log(1);
			scanCode();
		})

		mui('body').on("tap", "#login", function() {
			$("#account, #password").blur();
			var account = $("#account").val();
			var passwd = $("#password").val();
			localStorage.setItem("userId", account);
			//判断账号密码是否为空
			if(account != "" && passwd != "") {   //账号密码都不为空时
				if(window.navigator.onLine == true) {  //如果网络连接正常
					require(weburl + model,"json","post",{
						phone: account,
						password: passwd
					},function(data){
						if(data.status==0){ 
							mui.alert(data.msg, " ", "确认", function() {},"div");
							return false;
						}
						var datastr = JSON.stringify(data);
						localStorage.setItem('token', data.token); //把获取的token 存起来
						//保存账号,下次登陆只需输入密码即可登陆
						localStorage.setItem("USERID", account);
						localStorage.setItem("reload", "1");
						openwin();
					},function(xhr, type, errorThrown){
						if (xhr.status==0) {
							mui.alert("网络错误，请检查您的网络设置！", " ", "确认", function() {},"div");
							return false;
						}else if(xhr.status==500){
							mui.alert("网络异常，请稍后再试！", " ", "确认", function() {},"div");
							return false;
						}
						mui.alert("请求超时，请稍后重试！", " ", "确认", function() {},"div");
					})
				} else {
					mui.alert("网络错误，请检查您的网络！", " ", "确认", function() {},"div");
				}
			} else {   //如果账号或者密码为空则弹出提示
				if (account == "") {//用户名为空
					mui.alert("用户名不能为空！", " ", "确认", function() {},"div");
				} else if(passwd == ""){//密码框为空
					mui.alert("密码不能为空！", " ", "确认", function() {},"div");
				}
			}
			
			
		})

		function openwin() {
			mui.openWindow("../index.html", "index1_1", {});
		}
		
		//点击忘记密码
		mui("body").on("tap","#forget",function(){
			mui.openWindow("../view/forgot_pas.html","forgot_pas");
		})
		
		//点击注册
		mui("body").on("tap","#register",function(){
			mui.openWindow("../view/register.html","register");
		})
	})

})